package Obj;

import Main.GameBegin;

import java.awt.*;
//所有元素的父类
public class GameObj {
    //图片啦
    Image  img;
    //宽高啦
    int width,height;
    //位置啦
    int x,y;
    //速度啦
    double speed;
    GameBegin gameBegin;
    //构造器
    public GameObj() {
    }
    public GameObj(Image img, int width, int height, int x, int y, double speed, GameBegin gameBegin) {
        this.img = img;
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.gameBegin = gameBegin;
    }
    public GameObj(Image img, int width, int height, int x, int y, double speed) {
        this.img = img;
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public Image getImg() {
        return img;
    }

    public void setImg(Image img) {
        this.img = img;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public GameBegin getGameBegin() {
        return gameBegin;
    }

    public void setGameBegin(GameBegin gameBegin) {
        this.gameBegin = gameBegin;
    }
    /**
     * 绘制元素自身方法
     * 此方法负责将元素的图像绘制到指定的Graphics对象上
     * 主要用于图形界面的渲染过程中，将元素可视化
     *
     * @param g Graphics对象，用于绘制图像
     */
    public void paintSelf(Graphics g) {
        // 绘制图像到指定坐标位置
        g.drawImage(img,x,y,null);
        y+= speed;
        if(y>=0){

        }
    }
    /**
     * 获取自身矩形的方法
     *
     * 该方法用于创建并返回一个表示当前对象位置和大小的Rectangle对象
     * 这在需要获取对象在二维空间中的边界或进行碰撞检测时非常有用
     *
     * @return Rectangle 一个新创建的Rectangle对象，其属性x、y、width、height与当前对象相同
     */
    public Rectangle getRec() {
        return new Rectangle(x,y,width,height);
    }
}
